package com.ruoyi.web.controller.dict;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dict.domain.TDictEquipmentType;
import com.ruoyi.dict.service.ITDictEquipmentTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备类型Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/system/type")
public class TDictEquipmentTypeController extends BaseController
{
    @Autowired
    private ITDictEquipmentTypeService tDictEquipmentTypeService;

    /**
     * 查询设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDictEquipmentType tDictEquipmentType)
    {
        startPage();
        List<TDictEquipmentType> list = tDictEquipmentTypeService.selectTDictEquipmentTypeList(tDictEquipmentType);
        return getDataTable(list);
    }

    /**
     * 导出设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDictEquipmentType tDictEquipmentType)
    {
        List<TDictEquipmentType> list = tDictEquipmentTypeService.selectTDictEquipmentTypeList(tDictEquipmentType);
        ExcelUtil<TDictEquipmentType> util = new ExcelUtil<TDictEquipmentType>(TDictEquipmentType.class);
        util.exportExcel(response, list, "设备类型数据");
    }

    /**
     * 获取设备类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(tDictEquipmentTypeService.selectTDictEquipmentTypeByCode(code));
    }

    /**
     * 新增设备类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDictEquipmentType tDictEquipmentType)
    {
        // 设置创建�?
        tDictEquipmentType.setCreatedBy(getUserId());
        return toAjax(tDictEquipmentTypeService.insertTDictEquipmentType(tDictEquipmentType));
    }

    /**
     * 修改设备类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDictEquipmentType tDictEquipmentType)
    {
        // 设置修改�?
        tDictEquipmentType.setUpdatedBy(getUserId());
        return toAjax(tDictEquipmentTypeService.updateTDictEquipmentType(tDictEquipmentType));
    }

    /**
     * 删除设备类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(tDictEquipmentTypeService.deleteTDictEquipmentTypeByCodes(codes));
    }
}
